package com.jiawa.wiki.controller;

import com.jiawa.wiki.domain.Ebook;
import com.jiawa.wiki.req.EbookQueryReq;
import com.jiawa.wiki.req.EbookReq;
import com.jiawa.wiki.resp.CommonResp;
import com.jiawa.wiki.resp.EbookResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.EbookService;
import com.jiawa.wiki.util.CopyUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Argus
 * @className TestController
 * @description: TODO
 * @date 2025-06-12 11:43
 * @Version V1.0
 */
@RestController
//@Controller 返回一个页面
public class EbookController {

    @Autowired
    private EbookService ebookService;


    @GetMapping("/list")
    public CommonResp<PageResp<EbookResp>> list(@Valid EbookReq ebookReq) {
        CommonResp<PageResp<EbookResp>> commonResp = new CommonResp<>();
        PageResp<EbookResp> ebookList = ebookService.getEbookList(ebookReq);
        commonResp.setContent(ebookList);
        return commonResp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody  EbookQueryReq ebookQueryReq) {
        CommonResp resp = new CommonResp<>();
        ebookService.save(ebookQueryReq);
        return resp;
    }

    @PostMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        return resp;
    }
}